package views;
import java.awt.BorderLayout;
import java.awt.Color;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.border.EmptyBorder;

import model.Model;


public class GTCarRental extends JFrame {

	private JPanel contentPane;
	JTabbedPane tabbedPane;
	private PersonInfoPanel personalInfoPanel;

	/**
	 * Create the frame.
	 */
	public GTCarRental() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JLabel image = new JLabel(new ImageIcon(GTCarRental.class.getResource("logo.png")));
		
		JPanel panel = new JPanel();
		panel.add(image);
		panel.setBackground(Color.WHITE);
		contentPane.add(panel, BorderLayout.NORTH);
		
		tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		contentPane.add(tabbedPane, BorderLayout.CENTER);
		
		LoginPanel loginPanel = new LoginPanel();
		tabbedPane.addTab("Log In/Create Account", null, loginPanel, null);
		
		personalInfoPanel = new PersonInfoPanel();
		tabbedPane.addTab("Personal Information", null, personalInfoPanel, null);
		
		RentACarPanel rentCarPanel = new RentACarPanel();
		tabbedPane.addTab("Rent A Car", null, rentCarPanel, null);
		
		RentInfoPanel rentalInfoPanel = new RentInfoPanel();
		tabbedPane.addTab("Rental Information", null, rentalInfoPanel, null);
		
		ManageCarsPanel manageCarsPanel = new ManageCarsPanel();
		tabbedPane.addTab("Manage Cars", null, manageCarsPanel, null);
		
		MaintReqPanel maintenanceRequestsPanel = new MaintReqPanel();
		tabbedPane.addTab("Maintenance Requests", null, maintenanceRequestsPanel, null);
		
		RentChgReqPanel rentalChangeRequestPanel = new RentChgReqPanel();
		tabbedPane.addTab("Rental Change Request", null, rentalChangeRequestPanel, null);
		
		ReportsPanel viewReportsPanel = new ReportsPanel();
		tabbedPane.addTab("View Reports", null, viewReportsPanel, null);
	}
	
	public void disableTabs()
	{
		tabbedPane.setEnabled(false);
	}
	
	public void setUser(String user)
	{
		tabbedPane.setEnabled(true);
		tabbedPane.setEnabledAt(0, true);
		tabbedPane.setEnabledAt(1, true);
		tabbedPane.setEnabledAt(2, true);
		tabbedPane.setEnabledAt(3, true);
		tabbedPane.setEnabledAt(4, true);
		tabbedPane.setEnabledAt(5, true);
		tabbedPane.setEnabledAt(6, true);
		tabbedPane.setEnabledAt(7, true);
		if (user == null)
		{
			System.out.println("here");
			tabbedPane.setEnabled(false);
		}
		else
		{
			if (user.equals("MEMBER"))
			{
				tabbedPane.setEnabledAt(4, false);
				tabbedPane.setEnabledAt(5, false);
				tabbedPane.setEnabledAt(6, false);
				tabbedPane.setEnabledAt(7, false);//mng car, maint req, rental 
			}
			else if (user.equals("ADMINISTRATOR"))
			{
				tabbedPane.setEnabledAt(1, false);
				tabbedPane.setEnabledAt(2, false);
				tabbedPane.setEnabledAt(3, false);
				tabbedPane.setEnabledAt(4, false);
				tabbedPane.setEnabledAt(5, false);
				tabbedPane.setEnabledAt(6, false);
			}
			else if (user.equals("EMPLOYEE"))
			{
				tabbedPane.setEnabledAt(1, false);
				tabbedPane.setEnabledAt(2, false);
				tabbedPane.setEnabledAt(3, false);
				//tabbedPane.setEnabledAt(4, false);
				tabbedPane.setEnabledAt(7, false);
			}
		}
		tabbedPane.revalidate();
	}

	public void populate() {
		personalInfoPanel.getMyPresenter().populate();
	}

}
